#include <iostream>
#include <stdio.h>
using namespace std;

const int maxn = 30000;
const int maxm = 500;

int num[maxn];
int father[maxn];
int rank[maxn];

void makeset(int n)
{
    for (int i = 0; i < n; i++) {
        father[i] = i;
        rank[i] = 1;
        num[i] = 1;
    }
}

int dsfind(int x)
{
    int t = x;
    int temp;

    while (father[x] != x) 
        x = father[x];

    while (father[t] != x) {
        temp = father[t];
        father[t] = x;
        rank[t] = 1;
        t = temp;
    }

    return x;
}

void dsunion(int x, int y)
{
    int root1 = dsfind(x);
    int root2 = dsfind(y);

    if (root1 == root2) 
        return;

    if (rank[root1] > rank[root2] ) {
        father[root2] = root1;
        num[root1] += num[root2];
    }
    else {
        father[root1] = root2;
        num[root2] += num[root1];
        if (rank[root1] == rank[root2]) {
            rank[root2] = rank[root2] + 1;
        }
    }
}

int main(int argc, char *argv[])
{
    freopen("1611in", "r", stdin);   
    freopen("1611out", "w", stdout);   
    int n, m, x, y, groupnum;

    while (/*cin >> n >> m*/ scanf("%d %d", &n, &m) && (n || m)) {
        makeset(n);
        while (m--) {
            //cin >> groupnum;
            //cin >> x;
            scanf("%d %d", &groupnum, &x);
            for(int i = 1; i < groupnum; i++) {
                //cin >> y;
                scanf("%d", &y);
                dsunion(x, y);
            }
        }
        printf("%d\n", num[dsfind(0)]);
    }

    return 0;
}
